#include "far.h"
#include "util.h"

#include "nmfield.h"
#include "nmfield.cpp"

#include <iostream>
#include <cassert>

#include "stdffield.h"
#include "stdffield.cpp"

using namespace std;
using namespace opsrc::stdf;

Far::Far()
{	
}

Far::Far(stdf_rec _stdfrec,  int _reclen, std::ios::pos_type _fileRecFirstBytePosition, int _orderindex, endian e, char* buf)
    :RecBase(_stdfrec, _reclen, _fileRecFirstBytePosition, _orderindex), en(e) {
    if (buf!=0)
        readFields(buf);
}

Far::~Far(){
}

const StdfField<unsigned int> Far::getCpuType() const  {
    return cpu_type;
}

void Far::setCpuType(StdfField<unsigned int> enValue) {
    this->cpu_type = enValue;
}

const StdfField<unsigned int> &Far::getStdfVersion() const {
    return this->stdf_ver;
}

void Far::setStdfVersion(StdfField<unsigned int> version) {
    this->stdf_ver = version;
}

void Far::readFields(char* buf) {
#if _DEBUG
    cout << "stdfrec= FAR , filebytestartposition= " <<   getFileRecByteStartPosition() << ", recbytecount= " << reclen <<endl;
#endif

     // read cpu type, 1U
    int curpos = 0;
    NmField<unsigned int, 1> cputyp(buf + curpos, en);
    cpu_type.set(cputyp.getData(), curpos, cputyp.getByteCount(), cputyp.getTotalByteCount());
    //cout << cpu_type.getData() << "|";
    
    curpos =+ cpu_type.getTotalByteCount();
    if ( curpos > reclen-1) return;
    NmField<unsigned int, 1> stdfver(buf + curpos, en);
    stdf_ver.set(stdfver.getData(), curpos, stdfver.getByteCount(), stdfver.getTotalByteCount());
}
